<template>
  <div class="app-container">
  <!--站点数据-->
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
      <el-form-item label="订单号" prop="tradeNo">
        <el-input
          v-model="queryParams.tradeNo"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单类型" prop="serviceType">
        <el-select
          v-model="queryParams.serviceType"
          placeholder="类型"
          clearable
          size="small"
        >
          <el-option :key="" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in serveTypeOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="创建时间" prop="time">
        <el-date-picker
          v-model="queryParams.time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="用户手机号" prop="userTel">
        <el-input
          v-model="queryParams.userTel"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="选择校区" prop="schoolId">
       <el-select v-model="queryParams.schoolId" placeholder="请选择" clearable filterable size="small" @keyup.enter.native="handleQuery" >
         <el-option :key="" :label="'全部'" :value="null" />
         <el-option
           v-for="dict in schoolOptions"
           :key="dict.key"
           :label="dict.value"
           :value="dict.key"
         />
       </el-select>
      </el-form-item>
      <el-form-item label="选择站点" prop="siteId">
       <el-select v-model="queryParams.siteId" placeholder="请选择" clearable filterable size="small" @keyup.enter.native="handleQuery" >
         <el-option :key="" :label="'全部'" :value="null" />
         <el-option
           v-for="dict in siteOptions"
           :key="dict.key"
           :label="dict.value"
           :value="dict.key"
         />
       </el-select>
      </el-form-item>
      <el-form-item label="跑腿员类型" prop="runnerType">
        <el-select v-model="queryParams.runnerType" placeholder="类型" clearable size="small" >
          <el-option :key="" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in runnerTypeOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="跑腿员姓名" prop="runnerName">
        <el-input
          v-model="queryParams.runnerName"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="状态"
          clearable
          size="small"
        >
          <el-option :key="" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in orderStatusOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="跑腿员手机" prop="runnerTel">
        <el-input
          v-model="queryParams.runnerTel"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="tabelList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="tradeNo" />
      <el-table-column label="订单号类型" align="center" prop="serviceTypeName" />
      <el-table-column label="跑腿员类型" align="center" prop="runnerTypeName" />
      <el-table-column label="跑腿员" align="center" prop="runnerName" />
      <el-table-column label="发单人" align="center" prop="sender" />
      <el-table-column label="所属校区" align="center" prop="schoolName" />
      <el-table-column label="所属站点" align="center" prop="siteName" />
      <el-table-column label="订单金额(元)" align="center" prop="fee" />
      <el-table-column label="实付金额(元)" align="center" prop="payFee" />
      <el-table-column label="状态" align="center" width="100px">
        <template slot-scope="scope">
          <div class="dian" :style="{'background':statusClass(scope.row.status)}" ></div>
          <span>{{scope.row.statusName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单创建时间" align="center" prop="createTime" />
      <el-table-column label="订单完成时间" align="center" prop="finishTime" />

      <el-table-column label="操作" align="center" width="240">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="handleUpdate(scope.row, '详情')"
          >查看详情</el-button>
          <!-- v-if="scope.row.status === 1" -->
          <el-button
            size="mini"
            type="danger"
            @click="handleCancel(scope.row)"
          >取消订单</el-button>

          <!-- v-if="scope.row.status == 4" -->
          <el-button
            style="margin-top: 10px;"
            size="mini"
            type="danger"
            @click="beforeFinish(scope.row)"
          >完成订单</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详细 -->
    <el-dialog title="详细" :visible.sync="detailOpen" width="1000px">
      <el-form ref="form" :model="form"  label-width="120px" size="mini">
        <el-row>
          <el-col :span="24">

            <el-col :span="12">

              <div style="display: flex;align-items: center;justify-content: flex-start;">
                <div class="dian" :style="{'background':statusClass(listDetail.order.status)}" ></div>
                <div style="margin-right: 60px;">
                  {{ listDetail.order.statusName}}
                </div>
                <div class="typeyuan" v-if="runnerTypeNameStatus(listDetail.runner.type)">
                  {{ runnerTypeNameStatus(listDetail.runner.type).substr(0,1) }}
                </div>
                接单员:
                {{ listDetail.runner.username?listDetail.runner.username:'暂无'}}，{{ listDetail.runner.mobile?listDetail.runner.mobile:'暂无'}}
              </div>
            </el-col>

            <el-col :span="12">
              <el-form-item label="接单类型：">{{ listDetail.runner.typeName ||'-' }}</el-form-item>
            </el-col>
          </el-col>
          <el-col :span="12">
            <div style="color: #000000; font-size: 18px;font-weight: bold;line-height: 28px;margin-bottom: 18px;">用户信息</div>
          </el-col>
          <el-col :span="12">
            <div style="color: #000000; font-size: 18px;font-weight: bold;line-height: 28px;margin-bottom: 18px;">跑腿员信息</div>
          </el-col>
          <el-col :span="24">
            <div style="width: 100%;height: 1px;background: rgb(190,190,190);margin-bottom: 12px;"></div>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户昵称：">{{ listDetail.user.nickName || '-' }}</el-form-item>
            <el-form-item label="手机号：">{{ listDetail.user.mobile || '-' }}</el-form-item>
            <el-form-item label="定位城市：">{{ listDetail.user.city || '-' }}</el-form-item>
            <!-- <el-form-item label="校区：">{{ listDetail.user.schoolName || '-' }}</el-form-item> -->
            <el-form-item label="历史发单：">{{ listDetail.user.totalCount }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名：">{{ listDetail.runner.username || '-' }}</el-form-item>
            <el-form-item label="手机号：">{{ listDetail.runner.mobile || '-' }}</el-form-item>
            <el-form-item label="类型：">{{listDetail.runner.typeName}}
              <!-- {{ runnerTypeNameStatus(listDetail.runner.typeName) }} -->
            </el-form-item>
            <el-form-item label="历史接单数：">{{ listDetail.runner.totalOrderCount  }}</el-form-item>
            <el-form-item label="评分：">{{ listDetail.runner.score }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-form ref="form" :model="form" :inline="true" label-width="120px" size="mini">
        <el-row>
          <el-col :span="12">
            <div style="color: #000000; font-size: 18px;font-weight: bold;line-height: 28px;margin-bottom: 18px;">订单信息</div>
          </el-col>
          <el-col :span="24">
            <div style="width: 100%;height: 1px;background: rgb(190,190,190);margin-bottom: 12px;"></div>
          </el-col>
          <el-col :span="24">
            <el-form-item label="订单编号：">{{ listDetail.order.tradeNo }}</el-form-item>
            <el-form-item label="创建时间：">{{ listDetail.order.createTime }}</el-form-item>
            <el-form-item label="付款时间：">{{ listDetail.order.payTime }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="城市：">{{ listDetail.order.site?listDetail.order.site.city:'-' }}</el-form-item>
            <el-form-item label="校区：">{{ listDetail.order.site?listDetail.order.site.schoolName:'-' }}</el-form-item>
            <el-form-item label="站点：">{{ listDetail.order.site?listDetail.order.site.name:'-' }}</el-form-item>
            <el-form-item label="取件码：" >{{ listDetail.order.goods ?listDetail.order.goods.code : '-' }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="服务类型：">{{ listDetail.order.serviceTypeName }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item v-if="listDetail.order.serviceType==1" label="取货地址：">
              {{ listDetail.order.site?listDetail.order.site.name:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.site?listDetail.order.site.mobile:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.site?listDetail.order.site.address:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
            </el-form-item>
            <el-form-item v-else label="取货地址：">
              {{ listDetail.order.address?listDetail.order.address.name:'-'}}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.address?listDetail.order.address.mobile:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.address?listDetail.order.address.address:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item v-if="listDetail.order.serviceType==1" label="收货地址：">
              {{ listDetail.order.address?listDetail.order.address.name:'-'}}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.address?listDetail.order.address.mobile:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.address?listDetail.order.address.address:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
            </el-form-item>
            <el-form-item v-else label="收货地址：">
              {{ listDetail.order.site?listDetail.order.site.name:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.site?listDetail.order.site.mobile:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
              {{ listDetail.order.site?listDetail.order.site.address:'-' }}&nbsp;&nbsp;&nbsp;&nbsp;
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="校区：">{{ listDetail.order.site?listDetail.order.site.schoolName:'-' }}</el-form-item>
            <el-form-item label="跑腿员实际取件时间：" label-width="160px">{{ listDetail.order? listDetail.order.getTime: '-' }}</el-form-item>
            <el-form-item label="取件时间：" >{{ listDetail.order.time || '-' }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="物品类型：">
              {{ listDetail.order.goods?listDetail.order.goods.typeList.join(','):'-' }}
            </el-form-item>
            <el-form-item label="重量：">
              {{ listDetail.order.goods ? (listDetail.order.goods.kg || 0) + 'kg':'-' }}
            </el-form-item>
            <el-form-item label="实际重量：">
              {{ listDetail.order.goods ? (listDetail.order.goods.weight || 0) + 'kg':'-' }}
            </el-form-item>
            <el-form-item label="订单备注：">
              {{ listDetail.order.goods?(listDetail.order.goods.remark || '-'):'-' }}
            </el-form-item>
            <el-form-item label="是否加急：">
              {{ listDetail.order.isAdditional==1?'是':'否' }}
            </el-form-item>
            <el-form-item label="小费：">
              {{ listDetail.order ? (listDetail.order.tip||0) + '元':'-'  }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="是否需要寄件：">
              {{ listDetail.order.goods?listDetail.order.goods.deliveryFlgName:'-' }}
            </el-form-item>
            <el-form-item label="是否指定快递公司：" label-width="140px">
              {{ listDetail.order.goods?listDetail.order.goods.logisticsFlgName:'-' }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="预计里程：">
              {{ listDetail.order.goods ? (listDetail.order.goods.km || 0) + 'km':'-' }}
            </el-form-item>
            <el-form-item label="实际里程：">
              {{ listDetail.order.goods ? (listDetail.order.goods.mileage || 0) + 'km':'-' }}
            </el-form-item>
            <el-form-item label="预计时长：">
              {{ listDetail.order.goods ? (listDetail.order.goods.min || 0) + 'min':'-' }}
            </el-form-item>
            <el-form-item label="实际时长：">
              {{ listDetail.order.goods ? (listDetail.order.goods.timeTaken || 0) + 'min':'-' }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="支付方式：">{{ listDetail.order.payTypeName }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="取货留证："></el-form-item>
          </el-col>
          <el-col :span="24" v-if="listDetail.order.goods && listDetail.order.goods.takenImgList">
            <img v-for="(item,index) in listDetail.order.goods.takenImgList" :src="item" :key="item" style="width: 30%;margin:0 1%;height: 200px;" alt="">
            <!-- <img src="" style="width: 30%;margin:0 1%;max-height: 200px" alt=""> -->
            <!-- <img src="" style="width: 30%;margin:0 1%;max-height: 200px" alt=""> -->
          </el-col>
          <el-col :span="24">
            <el-form-item label="快递公司：">
              {{ listDetail.order.goods?listDetail.order.goods.logisticsName:'-' }}
            </el-form-item>
            <el-form-item label="快递单号：">
              {{ listDetail.order.goods?listDetail.order.goods.logisticsCode:'-' }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="跑腿员备注：">{{ listDetail.order.remark }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-form ref="form" :model="form"  label-width="120px" size="mini">
        <el-row>
          <el-col :span="12">
            <div style="color: #000000; font-size: 18px;font-weight: bold;line-height: 28px;margin-bottom: 18px;">费用明细</div>
          </el-col>
          <el-col :span="24">
            <div style="width: 100%;height: 1px;background: rgb(190,190,190);margin-bottom: 12px;"></div>
          </el-col>
          <el-col :span="12">
            <div v-if="listDetail.order.price && listDetail.order.price.priceDetailList">
              <el-form-item v-for="(item,index) in listDetail.order.price.priceDetailList" :label="item.name">{{ item.price }}元</el-form-item>
            </div>
            <!-- <el-form-item label="里程费：">{{ listDetail.order.xxxx }}</el-form-item>
            <el-form-item label="续重费：">{{ listDetail.order.xxxx }}</el-form-item>
            <el-form-item label="加急费：">{{ listDetail.order.xxxx }}</el-form-item>
            <el-form-item label="加时费：">{{ listDetail.order.xxxx }}</el-form-item>
            <el-form-item label="服务费：">{{ listDetail.order.xxxx }}</el-form-item>
            <el-form-item label="优惠券：">{{ listDetail.order.xxxx }}</el-form-item> -->
            <el-form-item label="实际收款:" v-if="listDetail.order.status == 0">
              {{ '待支付' }}
            </el-form-item>
            <el-form-item label="实际收款:" v-else>
              {{ listDetail.order.price?listDetail.order.price.price + '元':'-' }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  listOrder,
  listOrderDetail,
  listOrderCancel,
  listOrderOption,
  invokeHallTaskConfirmReceived,
  cuserOrderDetail,
  invokeOrderConfirm,
} from "@/api/pt/order";
import { runnerOption } from "@/api/pt/runner.js";
import { listSchool } from "@/api/pt/school.js";
import { listSite } from "@/api/pt/site.js";
import { getToken } from "@/utils/auth";
import { areajson } from "@/utils/area.js";
/* 订单流程。 1.待支付 2.待接单 3.未取货 4.已取货 5.已送达 6.待评价 7完成
0123456 */
export default {
  name: "Cuser",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户表格数据
      tabelList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 已有校区所在城市数据
      ownCity: [],
      // 已有下拉
      schoolOptions: [],
      siteOptions: [],
      runnerTypeOptions: [],
      orderStatusOptions: [],
      serveTypeOptions: [],
      // 城市数据
      cityOptions: areajson,
      // 表单参数
      form: {},
      //详情打开
      detailOpen: false,
      listDetail: {
        order: {},
        runner: {},
        user: {},
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        runnerName: undefined,
        runnerTel: undefined,
        runnerType: undefined,
        schoolId: undefined,
        serviceType: undefined,
        siteId: undefined,
        tradeNo: undefined,
        userTel: undefined,
        status: "",
        time: "",
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "站点名称不能为空", trigger: "blur" },
        ],
        schoolId: [{ required: true, message: "请选择校区", trigger: "blur" }],
        address: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
        time: [{ required: true, message: "请选择时间", trigger: "blur" }],
        email: [
          { required: true, message: "邮箱地址不能为空", trigger: "blur" },
          {
            type: "email",
            message: "'请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        phone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  created() {
    this.getList();
    listOrderOption().then((response) => {
      this.runnerStatusOptions = response.data.state;
      this.runnerTypeOptions = response.data.type;
      this.schoolOptions = response.data.school;
      this.siteOptions = response.data.site;
      this.runnerTypeOptions = response.data.runnerType;
      this.orderStatusOptions = response.data.status;
      this.serveTypeOptions = response.data.type;
    });
  },
  methods: {
    statusClass(e) {
      /* 订单流程。 1.待支付 2.待接单 3.未取货 4.已取货 5.已送达 6.待评价 7完成
          0123456*/
      let color = "";
      switch (e) {
        case 0:
          color = "rgb(244,84,84)";
          break;
        case 1:
          color = "rgb(230,35,16)";
          break;
        case 2:
          color = "rgb(27,154,204)";
          break;
        case 3:
          color = "rgb(27,154,204)";
          break;
        case 4:
          color = "rgb(0,215,255)";
          break;
        case 5:
          color = "rgb(27,255,204)";
          break;
        case 6:
          color = "rgb(12,208,62)";
          break;
        default:
          color = "rgb(208,197,197)";
      }
      return color;
    },
    /* 用户状态 */
    runnerTypeNameStatus(str) {
      if (str === 0) {
        return "普通";
      } else if (str === 1) {
        return "平台";
      } else if (str === "0") {
        return "普通";
      } else if (str === "1") {
        return "平台";
      } else {
        return "";
      }
    },
    /* 用户状态 */
    cuserState(str) {
      if (str === 0) {
        return "正常";
      } else if (str === 1) {
        return "冻结中";
      } else if (str === 2) {
        return "已拉黑";
      } else if (str === 3) {
        return "已注销";
      }
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listOrder(
        this.addDateRange2(this.queryParams, "createTimeStart", "createTimeEnd")
      ).then((response) => {
        this.tabelList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    getDetail(tradeNo) {
      listOrderDetail(tradeNo).then((response) => {
        let data = response.data;
        this.listDetail.runner = data.runner ? data.runner : {};
        this.listDetail.user = data.user ? data.user : {};
        this.listDetail.order = data.order ? data.order : {};
      });
    },
    beforeFinish(row){
      let that = this
      this.$confirm("确认要完成订单吗?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
      .then(function (res) {
        console.log(res)
        if(res = 'confirm') {
          that.finishOrder(row)
        }
      })
      .catch(function () {
        console.log(3)
      });
      return
    },
    finishOrder(row) {
      // 调用客户送达接口
      invokeOrderConfirm({
        tradeNo: row.tradeNo,
        flg: 1,
      })
      .then((res) => {
        this.msgSuccess("操作成功");
        this.getList()
      });
    },
    finishOrder1(row){
      //调用跑腿员送达接口
      cuserOrderDetail(row.tradeNo, { latitude: 30.250979, longitude: 120.163199, }).then((response) => {
        let data = response.data;
        if(data.serviceType == 1) {
          var pa = {
            // logisticsName = data.order.goods.logisticsName,
            no: row.tradeNo,
            message: '完成！',
            code: data.ucode,
            logisticsCode: "",
            logisticsName: "",
            memo: "",
          }
        } else {
          var pa = {
            // logisticsName: data.order.goods.logisticsName,
            no: row.tradeNo,
            message: '完成！',
            code: undefined,
            logisticsCode: "",
            logisticsName: "",
            memo: "",
          }
        }
        invokeHallTaskConfirmReceived(pa).then((response)=>{
          if (response.code !== 200) {
            this.msgError(response.message);
            return;
          } else {
            this.msgSuccess("操作成功");
            this.getList()
          }
        }).catch((err)=>{
          // console.log(err)
        })
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === 0 ? "启用" : "关闭";
      this.$confirm("确认要" + text + '"' + row.name + '"吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          row.time = [new Date(row.startTime), new Date(row.endTime)];
          return addSchool(row);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
      this.form = {
        id: undefined,
        schoolId: undefined,
        name: undefined,
        city: undefined,
        status: undefined,
        address: undefined,
        siteDescribe: undefined,
        personInCharge: undefined,
        mobile: undefined,
        personInCharge2: undefined,
        mobile2: undefined,
        time: undefined,
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      console.log(row);
      this.title = "修改";
      row.time = [new Date(row.startTime), new Date(row.endTime)];
      this.form = row;
      if (type === "详情") {
        this.detailOpen = true;
        this.getDetail(this.form.tradeNo);
      } else {
        this.open = true;
      }
    },

    /** 删除按钮操作 */
    handleCancel(row) {
      const tradeNo = row.tradeNo;
      let text = "";
      text = `是否取消订单？`;
      this.$confirm(text, "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return listOrderCancel(tradeNo);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("取消成功");
        })
        .catch(function () {});
    },

    // 获取当前选中校区所在城市
    selectSchool(val) {
      this.schoolOptions.map((item) => {
        if (item.id === val) this.form.city = item.city;
      });
    },
  },
};
</script>

<style type="text/css">
.dian {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: #999;
  margin-right: 6px;
}
.typeyuan {
  width: 25px;
  height: 25px;
  line-height: 25px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  border: 1px solid #999;
  vertical-align: middle;
  text-align: center;
}
</style>
